package com.datastructure.test.maxlengthofrepeatingserial;

public class MaxLengthOfRepeatingSerial {

    public static void main(String[] args) {
        MaxLengthOfRepeatingSerial maxLengthOfRepeatingSerial = new MaxLengthOfRepeatingSerial();
        String data ="abcab";
        int ababc = maxLengthOfRepeatingSerial.solve(data);
        System.out.println(ababc);
    }

    public int solve (String a) {
        // write code here
        int length = a.length();
        int max = 0;
        String sub1;
        String sub2;
        String temp;
        for (int i = 0; i < a.length(); i++) {
            temp=a.substring(i,length);
            int tempLength = temp.length();
            for (int j = 0; j < tempLength/2+1; j++) {
                sub1=temp.substring(0,j);
                sub2=temp.substring(j,tempLength);
                if(sub2.startsWith(sub1)){
                    max=Math.max(max,sub1.length()*2);
                }
            }
        }
        return max;
    }
}
